﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using Liolikas.LiolikasGame;
using Liolikas.GameBoard;
using System.Threading.Tasks;

namespace Liolikas.GameObjects
{
    class PlayerChar : Character
    {
        public static String CAUGHT_MODEL = ":(";
        public static String STANDART_MODEL = ":P";
        static PlayerChar playerChar;
        
        public List<int[]> outDatedCoordinates = new List<int[]>();
        PlayerChar(int hCoord, int wCoord):base(hCoord,wCoord)
        {
             base.model = STANDART_MODEL;
             //base.objectBackgroundColor = ConsoleColor.Green;
             base.objectColor = ConsoleColor.Green;
        }

        

        public static PlayerChar GetPlayerChar(){
            if (playerChar == null)
                playerChar = new PlayerChar(Board.BOARD_HEIGHT / 2, Board.BOARD_WIDTH / 2);

            return playerChar;
        }

        override public void GetNewCoordinates()
        {
            ConsoleKey inputKey = Console.ReadKey(true).Key;
            lastHCoord = hCoord;
            lastWCoord = wCoord;
            int[] lastCoordinates = {lastHCoord, lastWCoord};
            outDatedCoordinates.Add(lastCoordinates);
            if (inputKey == ConsoleKey.UpArrow) hCoord--;
            else if (inputKey == ConsoleKey.DownArrow) hCoord++;
            else if (inputKey == ConsoleKey.LeftArrow) wCoord--;
            else if (inputKey == ConsoleKey.RightArrow) wCoord++;           
        }
        override public void MakeStep()
        {            
            GetNewCoordinates();
            if (hCoord < 0 || hCoord >= Board.BOARD_HEIGHT) hCoord = lastHCoord;
            if (wCoord < 0 || wCoord + model.Length > Board.BOARD_WIDTH) wCoord = lastWCoord;
            if (lastHCoord != hCoord || lastWCoord != wCoord) UpdateCoordinates();
        }
        override public void Collide(GameObject gameObj)
        {
            if (!Game.GetGame().isOver)
            {
                if (gameObj is Abalys)
                {
                    Game.GetGame().isOver = true; 
                    Renderer.LiolikasCaught();
                }
            }
        }

    }
}
